import QtQuick 2.15
import QtQuick.Controls 2.15
import MyLib 1.0

Item {
    property real button1: thrumasterRocker.button1
    property real button2: thrumasterRocker.button2
    property real button3: thrumasterRocker.button3
    property real trigger1: thrumasterRocker.trigger1
    property real trigger2: thrumasterRocker.trigger2
    property real axis4: thrumasterRocker.axis4
    property real axis5: thrumasterRocker.axis5
    property real axis81: thrumasterRocker.axis81
    property real axis82: thrumasterRocker.axis82
    property real rockerX: thrumasterRocker.rockerX
    property real rockerY: thrumasterRocker.rockerY

    property real button21: thrumasterPusher.button1
    property real button22: thrumasterPusher.button2
    property real button23: thrumasterPusher.button3
    property real switcher21: thrumasterPusher.switcher21
    property real switcher22: thrumasterPusher.switcher22
    property real switcher23: thrumasterPusher.switcher23
    property real switcher24: thrumasterPusher.switcher24
    property real switcher25: thrumasterPusher.switcher25
    property real switcher31: thrumasterPusher.switcher31
    property real switcher32: thrumasterPusher.switcher32
    property real switcher33: thrumasterPusher.switcher33
    property real switcher34: thrumasterPusher.switcher34
    property real switcher35: thrumasterPusher.switcher35
    property real switcher36: thrumasterPusher.switcher36
    property real switcher37: thrumasterPusher.switcher37
    property real switcher38: thrumasterPusher.switcher38
    property real axis42: thrumasterPusher.axis4
    property real axis8: thrumasterPusher.axis8
    property real slider: thrumasterPusher.slider
    property real axisSliderX: thrumasterPusher.axisSliderX
    property real axisSliderY: thrumasterPusher.axisSliderY
    property real axisSliderPressed: thrumasterPusher.axisSliderPressed
    property real pusher1: thrumasterPusher.pusher1
    property real pusher2: thrumasterPusher.pusher2

    Column {
        id: rocker
        anchors {
            top: parent.top
            bottom: parent.bottom
            left: parent.left
        }
        width: 200

        Repeater {
            model: [
                {"id": 1, "title": "Button1", "value": button1},
                {"id": 1, "title": "Button2", "value": button2},
                {"id": 1, "title": "Button3", "value": button3},
                {"id": 2, "title": "Trigger1", "value": trigger1},
                {"id": 2, "title": "Trigger2", "value": trigger2},
                {"id": 3, "title": "Axis4", "value": axis4},
                {"id": 3, "title": "Axis5", "value": axis5},
                {"id": 3, "title": "Axis81", "value": axis81},
                {"id": 3, "title": "Axis82", "value": axis82},
                {"id": 4, "title": "RockerX", "value": rockerX},
                {"id": 4, "title": "RockerY", "value": rockerY},
            ]
            anchors.fill: parent

            Row {
                height: 40
                width: parent.width

                Text {
                    id: title
                    text: modelData.title
                    height: parent.height
                    width: parent.width / 2
                    font.pointSize: height / 3
                }

                Text {
                    id: value
                    height: parent.height
                    width: parent.width / 2
                    font.pointSize: height / 3
                }

                Component.onCompleted: {
                    switch(modelData.id) {
                    case 1:
                    case 2:
                        value.text = (modelData.value === JoystickReader.Button_PUSHED)? "按下" : "释放";
                        break;
                    case 3:
                        if(modelData.value === JoystickReader.Axis_RELEASE)
                            value.text = "释放";
                        else if(modelData.value === JoystickReader.Axis_PRESSED)
                            value.text = "按下";
                        else if(modelData.value === JoystickReader.Axis_UP)
                            value.text = "向上";
                        else if(modelData.value === JoystickReader.Axis_DOWN)
                            value.text = "向下";
                        else if(modelData.value === JoystickReader.Axis_LEFT)
                            value.text = "向左";
                        else if(modelData.value === JoystickReader.Axis_RIGHT)
                            value.text = "向右";
                        else if(modelData.value === JoystickReader.Axis_LEFT_UP)
                            value.text = "左上";
                        else if(modelData.value === JoystickReader.Axis_LEFT_DOWN)
                            value.text = "左下";
                        else if(modelData.value === JoystickReader.Axis_RIGHT_UP)
                            value.text = "右上";
                        else if(modelData.value === JoystickReader.Axis_RIGHT_DOWN)
                            value.text = "右下";
                        break;
                    case 4:
                        value.text = modelData.value.toFixed(2)
                        break;
                    }
                }
            }
        }
    }

    Column {
        id: pusher
        anchors {
            top: parent.top
            bottom: parent.bottom
            left: rocker.right
        }
        width: 200

        Repeater {
            anchors.fill: parent
            model: [
                {"id": 1, "title": "Button1", "value": button21},
                {"id": 1, "title": "Button2", "value": button22},
                {"id": 1, "title": "Button3", "value": button23},
                {"id": 2, "title": "Switcher21", "value": switcher21},
                {"id": 2, "title": "Switcher22", "value": switcher22},
                {"id": 2, "title": "Switcher23", "value": switcher23},
                {"id": 2, "title": "Switcher24", "value": switcher24},
                {"id": 2, "title": "Switcher25", "value": switcher25},
                {"id": 3, "title": "Switcher31", "value": switcher31},
                {"id": 3, "title": "Switcher32", "value": switcher32},
                {"id": 3, "title": "Switcher33", "value": switcher33},
                {"id": 3, "title": "Switcher34", "value": switcher34},
                {"id": 3, "title": "Switcher35", "value": switcher35},
                {"id": 3, "title": "Switcher36", "value": switcher36},
                {"id": 3, "title": "Switcher37", "value": switcher37},
                {"id": 3, "title": "Switcher38", "value": switcher38},
                {"id": 4, "title": "Axis4", "value": axis42},
                {"id": 4, "title": "Axis8", "value": axis8},
                {"id": 5, "title": "Slider", "value": slider},
                {"id": 5, "title": "AxisSliderX", "value": axisSliderX},
                {"id": 5, "title": "AxisSliderY", "value": axisSliderY},
                {"id": 5, "title": "Pusher1", "value": pusher1},
                {"id": 5, "title": "Pusher2", "value": pusher2}
            ]

            Row {
                height: 40
                width: parent.width

                Text {
                    id: title1
                    text: modelData.title
                    height: parent.height
                    width: parent.width / 2
                    font.pointSize: height / 3
                }

                Text {
                    id: value1
                    height: parent.height
                    width: parent.width / 2
                    font.pointSize: height / 3
                }

                Component.onCompleted: {
                    switch(modelData.id) {
                    case 1:
                        value1.text = (modelData.value === JoystickReader.Button_PUSHED)? "按下" : "释放";
                        break;
                    case 2:
                        value1.text = (modelData.value === JoystickReader.Switcher2_ON)? "打开" : "关闭";
                        break;
                    case 3:
                        if(modelData.value === JoystickReader.Switcher3_UP)
                            value1.text = "上拨";
                        else if(modelData.value === JoystickReader.Switcher3_DOWN)
                            value1.text = "下拨";
                        else if(modelData.value === JoystickReader.Switcher3_MID)
                            value1.text = "中间";
                        break;
                    case 4:
                        if(modelData.value === JoystickReader.Axis_RELEASE)
                            value1.text = "释放";
                        else if(modelData.value === JoystickReader.Axis_PRESSED)
                            value1.text = "按下";
                        else if(modelData.value === JoystickReader.Axis_UP)
                            value1.text = "向上";
                        else if(modelData.value === JoystickReader.Axis_DOWN)
                            value1.text = "向下";
                        else if(modelData.value === JoystickReader.Axis_LEFT)
                            value1.text = "向左";
                        else if(modelData.value === JoystickReader.Axis_RIGHT)
                            value1.text = "向右";
                        else if(modelData.value === JoystickReader.Axis_LEFT_UP)
                            value1.text = "左上";
                        else if(modelData.value === JoystickReader.Axis_LEFT_DOWN)
                            value1.text = "左下";
                        else if(modelData.value === JoystickReader.Axis_RIGHT_UP)
                            value1.text = "右上";
                        else if(modelData.value === JoystickReader.Axis_RIGHT_DOWN)
                            value1.text = "右下";
                        break;
                    case 5:
                        value1.text = modelData.value.toFixed(2)
                        break;
                    }
                }
            }
        }
    }
}
